package com.itheima.reggie.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 基于Thread Local封装的工具类，用于保存和获取当前登录的Id
 */
@Component
@Slf4j
public class BaseContext {
    private static final ThreadLocal<Long> threadLocal = new ThreadLocal<>();
    private static final ThreadLocal<Long> threadLocal2 = new ThreadLocal<>();

    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }
    public static Long getCurrentId(){
        return threadLocal.get();
    }
    /**
     * 释放线程中的数据
     */
    public static void remove(){
        threadLocal.remove();
    }

}
